﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
//new

namespace JKZP
{
    public partial class ChangeForm : Form
    {
        public ChangeForm()
        {
            InitializeComponent();
        }

        private void ChangeForm_Load(object sender, EventArgs e)
        {
            textBox_username.Text = PP.gUser.username;
        }

        private void button_save_Click(object sender, EventArgs e)
        {
            if (maskedTextBox_old.Text == "")
            {
                this.toolStripStatusLabel1.Text = "请输入旧密码";
                return;
            }
            if (maskedTextBox_new1.Text == "")
            {
                this.toolStripStatusLabel1.Text = "请输入新密码";
                return;
            }
            if (maskedTextBox_new2.Text == "")
            {
                this.toolStripStatusLabel1.Text = "请再次输入新密码";
                return;
            }
            if (maskedTextBox_new1.Text != maskedTextBox_new2.Text)
            {
                this.toolStripStatusLabel1.Text = "新密码输入不一致";
                return;
            }
            if (maskedTextBox_old.Text != PP.gUser.password)
            {
                this.toolStripStatusLabel1.Text = "旧密码错误";
                return;
            }

            if (PP.gISWebVersion == false)
            {
                if (PP.SavePassWord(maskedTextBox_new1.Text) == true)
                {
                    PP.gUser.password = maskedTextBox_new1.Text;
                    this.toolStripStatusLabel1.Text = "保存成功";
                }
                else
                {
                    this.toolStripStatusLabel1.Text = "保存失败";
                }
            }
            else
            {
                bool flag = PP.kdws.JKZP_ChangePassword(PP.gUser.username, PP.gUser.password, maskedTextBox_new1.Text);
                if (flag == true)
                {
                    PP.gUser.password = maskedTextBox_new1.Text;
                    this.toolStripStatusLabel1.Text = "保存成功";
                }
                else
                {
                    this.toolStripStatusLabel1.Text = "保存失败";
                }
            }
        }

        private void button_exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        

    }
}
